<template>
  <div>
    <el-dialog title="车辆维修保养" :visible="dialogVisible" @close="close">
      <el-form :model="formData" :rules="rules" ref="form">
        <el-row>
          <el-col :sm="12">
            <el-form-item label="申报车辆" prop="enName" label-width="100px">
              <el-select v-model="formData.enName" placeholder="申报车辆">
                <el-option label="xxx" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :sm="12">
            <el-form-item label="维修单位" prop="enName" label-width="100px">
              <el-input v-model="formData.enName" placeholder="维修单位"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :sm="12">
            <el-form-item label="费用预算" prop="enName" label-width="100px">
              <el-input v-model="formData.enName" type="number" placeholder="加油金额"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :sm="24">
            <el-form-item label="维修项目" prop="enName" label-width="100px">
              <el-input v-model="formData.enName" type="textarea" placeholder="维修项目"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :sm="24">
            <el-form-item label="备注信息" prop="enName" label-width="100px">
              <el-input v-model="formData.enName" type="textarea" placeholder="备注信息"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { checkPerm, addPerm } from "@/api/role";
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      /**
       * 
        private Permission parent.pid;
        private String menuName;
        private String showOrder;
        private String url;
        private String enName;
       */
      formData: {
        "parent.pid": "",
        parentPid: "",
        menuName: "",
        showOrder: "",
        url: "",
        enName: ""
      },
      rules: {
        menuName: [{ required: true, message: "请输入", trigger: "blur" }],
        enName: [{ required: true, message: "请输入", trigger: "blur" }]
      }
    };
  },
  methods: {
    close() {
      this.$emit("update:dialogVisible", false);
    },
    save() {
      this.$refs["form"].validate(async valid => {
        if (valid) {
          let d = await checkPerm({
            name: this.formData.enName
          });
          if (!d) {
            this.$message({
              message: "代码重复",
              type: "error"
            });
            return;
          }
          this.formData["parent.pid"] = this.formData.parentPid;
          let r = await addPerm(this.formData);
          if (r && r.error == 0) {
            this.$refs["form"].resetFields();
            this.$emit("finish", r);
            this.close();
          } else {
            this.$message({
              message: "出错了",
              type: "error"
            });
          }
        } else {
          return false;
        }
      });
    }
  }
};
</script>
